package com.gzsxy.esjy.service.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzsxy.esjy.bus.log.annotation.OperLog;
import com.gzsxy.esjy.bus.log.enum1.LogActionType;
import com.gzsxy.esjy.service.base.dto.request.ProductGroups;
import com.gzsxy.esjy.service.base.dto.request.ProductRequest;
import com.gzsxy.esjy.service.base.dto.request.VerifyRequest;
import com.gzsxy.esjy.service.base.dto.response.DefaultResponse;
import com.gzsxy.esjy.service.base.dto.response.PageResult;
import com.gzsxy.esjy.service.base.dto.response.VerifyRsp;
import com.gzsxy.esjy.service.product.entity.Product;
import com.gzsxy.esjy.service.product.entity.vo.VerifyQueryVo;
import com.gzsxy.esjy.service.product.service.VerifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 商品审核
 * @date 2022/1/27 16:10
 */
@CrossOrigin  //解决跨域
@RefreshScope    //动态刷新配置文件-外部配置文件
@RestController
@RequestMapping("/admin/verify")
@Api("商品审核管理")
public class VerifyController {

    @Autowired
    private VerifyService verifyService;



    @GetMapping("/list")
    @ApiOperation("查询审核商品")
    public DefaultResponse getVerifyProduct(@ApiParam(value = "当前页面",required = false,defaultValue ="1" ) @RequestParam(required = false) Long page,         //long数据类型适用于较大整数类型
                                            @ApiParam(value = "每页记录数",required = false,defaultValue ="5") @RequestParam(required = false) Long limit,
                                            @ApiParam("查询对象") VerifyQueryVo verifyQueryVo){
        IPage<Product> pageParam = null;
        //分页查询
        if (page != null && limit != null){
            pageParam = new Page<>(page, limit);
        }
        PageResult<VerifyRsp> verifyRspList = verifyService.getVerifyProduct(pageParam,verifyQueryVo);
        return DefaultResponse.ok(verifyRspList);
    }

    @PutMapping("/edit")
    @ApiOperation("修改审核信息")
    @OperLog(operModul = "商品审核管理",operType = LogActionType.UPDATE,operDesc = "修改审核信息")
    public DefaultResponse editVerify(@Validated({ProductGroups.class}) @RequestBody VerifyRequest verifyRequest
                                      ){
        verifyService.editVerify(verifyRequest);
        return DefaultResponse.ok();
    }



}
